﻿CREATE TABLE [dbo].[Customer] (
    [Id]                     INT              IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL,
    [CompanyId]              INT              NULL,
    [CustomerId]             UNIQUEIDENTIFIER NULL,
    [CustomerName]           NVARCHAR (200)   NULL,
    [MnemonicWorks]          NVARCHAR (50)    NULL,
    [Project]                NVARCHAR (200)   NULL,
    [WebAddress]             VARCHAR (50)     NULL,
    [ZName]                  NVARCHAR (50)    NULL,
    [Tel]                    VARCHAR (50)     NULL,
    [Fax]                    VARCHAR (50)     NULL,
    [Pid]                    INT              NULL,
    [Cid]                    INT              NULL,
    [Rid]                    INT              NULL,
    [Address]                NVARCHAR (200)   NULL,
    [Zip]                    VARCHAR (50)     NULL,
    [IndustryOneId]          INT              NULL,
    [IndustryTwoId]          INT              NULL,
    [SourceId]               INT              NULL,
    [StateId]                INT              NULL,
    [TypeId]                 INT              NULL,
    [CreateName]             VARCHAR (50)     CONSTRAINT [DF_Customer_CreateName] DEFAULT (getdate()) NULL,
    [CreateDate]             DATETIME         NULL,
    [ProtectId]              INT              NULL,
    [ProtectName]            VARCHAR (50)     NULL,
    [ProtectDate]            DATETIME         NULL,
    [TrackDate]              DATETIME         NULL,
    [Audit]                  BIT              CONSTRAINT [DF_Customer_Audit] DEFAULT ((0)) NULL,
    [UpTime]                 DATETIME         NULL,
    [IntentionsId]           INT              CONSTRAINT [DF_Customer_IntentionsId] DEFAULT ((0)) NULL,
    [PublicityDemandId]      INT              CONSTRAINT [DF_Customer_PublicityDemandId] DEFAULT ((0)) NULL,
    [NetworkConsciousnessId] INT              CONSTRAINT [DF_Customer_NetworkConsciousnessId] DEFAULT ((0)) NULL,
    [SalesPerson]            VARCHAR (50)     NULL,
    [ServicePerson]          VARCHAR (50)     NULL,
    [AuditPerson]            VARCHAR (50)     NULL,
    [delFlag]                SMALLINT         CONSTRAINT [DF_Customer_delFlag] DEFAULT ((0)) NOT NULL,
    [OrdersCount]            INT              CONSTRAINT [DF_Customer_OrdersCount] DEFAULT ((0)) NOT NULL,
    [ExtractDate]            INT              CONSTRAINT [DF_Customer_w] DEFAULT (datediff(day,'1900-1-1',getdate())) NOT NULL,
    [BDServicePerson]        VARCHAR (20)     CONSTRAINT [DF_Customer_BDServicePerson_1] DEFAULT ('') NULL,
    [BDServicePersonEName]   NVARCHAR (50)    CONSTRAINT [DF_Customer_BDServicePersonEName_1] DEFAULT ('') NULL,
    [BDServiceDate]          DATETIME         NULL,
    [ServicePersonEName]     NVARCHAR (50)    CONSTRAINT [DF_Customer_ServicePersonEName_1] DEFAULT ('') NULL,
    [ServiceDate]            DATETIME         NULL,
    [RegTime]                DATETIME         NULL,
    [RegCapital]             DECIMAL (18, 2)  NULL,
    [Employees]              INT              NULL,
    [Introduction]           NVARCHAR (MAX)   NULL,
    CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED ([Id] ASC)
);


GO
CREATE NONCLUSTERED INDEX [IX_CustomerID]
    ON [dbo].[Customer]([CustomerId] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_CustomerName]
    ON [dbo].[Customer]([CustomerName] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_Customer_Audit]
    ON [dbo].[Customer]([Audit] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_Customer_CompanyId]
    ON [dbo].[Customer]([CompanyId] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_Customer_ProtectName]
    ON [dbo].[Customer]([ProtectName] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_Customer_ServicePersonEName]
    ON [dbo].[Customer]([ServicePersonEName] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_Customer_ServicePerson]
    ON [dbo].[Customer]([ServicePerson] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_Customer_BDServicePerson]
    ON [dbo].[Customer]([BDServicePerson] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_Customer_BDServicePersonEName]
    ON [dbo].[Customer]([BDServicePersonEName] ASC);


GO
CREATE NONCLUSTERED INDEX [EFS_IX_Customer_9d6fbd92c4d04ce9b62154e169692d7c]
    ON [dbo].[Customer]([ProtectId] ASC, [ProtectName] ASC);


GO
CREATE NONCLUSTERED INDEX [EFS_IX_Customer_7d37b598499b43d996521fa4292f6165]
    ON [dbo].[Customer]([CompanyId] ASC, [Audit] ASC)
    INCLUDE([Id], [CustomerId], [CustomerName], [MnemonicWorks], [SourceId], [CreateName], [CreateDate], [ProtectId]);


GO
CREATE NONCLUSTERED INDEX [EFS_IX_Customer_9454f60c02c848acaf85aa4fa3c01805]
    ON [dbo].[Customer]([CompanyId] ASC, [Audit] ASC, [delFlag] ASC, [BDServicePerson] ASC)
    INCLUDE([CustomerName]);


GO
CREATE NONCLUSTERED INDEX [EFS_IX_Customer_eaa14431ed6f43308c6855f1ee7dc48a]
    ON [dbo].[Customer]([CompanyId] ASC, [CreateDate] ASC)
    INCLUDE([CustomerName]);


GO
CREATE NONCLUSTERED INDEX [EFS_IX_Customer_60366c896f3f47eeabaeb73975c844de]
    ON [dbo].[Customer]([CompanyId] ASC, [ProtectId] ASC, [ProtectName] ASC, [ExtractDate] ASC);


GO
CREATE NONCLUSTERED INDEX [EFS_IX_Customer_0ec109d3fd12448385b082d76ddc6aeb]
    ON [dbo].[Customer]([CompanyId] ASC, [ProtectId] ASC, [ProtectName] ASC, [Audit] ASC, [delFlag] ASC, [OrdersCount] ASC, [UpTime] ASC)
    INCLUDE([Id], [CustomerName]);


GO
CREATE NONCLUSTERED INDEX [EFS_IX_Customer_fb8155d9916a4006832b7e23ffd1efb8]
    ON [dbo].[Customer]([CompanyId] ASC, [IndustryOneId] ASC, [IndustryTwoId] ASC, [ProtectId] ASC, [ProtectName] ASC, [Audit] ASC, [delFlag] ASC, [OrdersCount] ASC, [UpTime] ASC)
    INCLUDE([Id], [CustomerName]);


GO
CREATE TRIGGER [dbo].[Customer_Deleted] On [dbo].[Customer]
AFTER DELETE
AS 
BEGIN
	Insert Into Recycler_Customer Select * From Deleted
END

GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'公司编号', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'CompanyId';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'客户编号', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'CustomerId';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'客户名称', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'CustomerName';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'助记词', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'MnemonicWorks';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'经营范围', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'Project';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'网址', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'WebAddress';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'联系人', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'ZName';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'联系电话', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'Tel';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'传真', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'Fax';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'省', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'Pid';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'市', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'Cid';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'区/县', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'Rid';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'联系地址', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'Address';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'邮编', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'Zip';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'1级行业', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'IndustryOneId';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'2级行业', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'IndustryTwoId';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'客户来源', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'SourceId';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'新老客户标志', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'StateId';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'客户类型', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'TypeId';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'创建者', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'CreateName';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'创建日期', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'CreateDate';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'跟踪/保护状态', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'ProtectId';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'跟踪/保护人', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'ProtectName';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'跟踪/保护日期', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'ProtectDate';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'批注日期', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'TrackDate';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'审核标志', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'Audit';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'最后批注日期', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'UpTime';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'客户意向', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'IntentionsId';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'推广需求', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'PublicityDemandId';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'网络意识', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'NetworkConsciousnessId';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'销售人员', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'SalesPerson';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'维护客福编号', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'ServicePerson';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'审核人', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'AuditPerson';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'删除标志', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'delFlag';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'成单数', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'OrdersCount';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'申领日期', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'ExtractDate';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'百度客服人员编号', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'BDServicePerson';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'百度客服人员姓名', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'BDServicePersonEName';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'分配百度客服时间', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'BDServiceDate';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'维护客服姓名', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'ServicePersonEName';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'分配维护客服的日期', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Customer', @level2type = N'COLUMN', @level2name = N'ServiceDate';

